//拼片DEMO函数
//宋恒早2019

function classReplace(el) {
  var pClass = el.getAttribute("class");
  var pFill = pClass.split(" ");
  switch (pFill[0]) {
    case "fil0":
      var newpFill = "fil1";
      break;
    case "fil1":
      var newpFill = "fil0";
      break;
    case "fil2":
      var newpFill = "fil1";
      break;
    default:
      alert("budui");
  }
  switch (pFill[1]) {
    case "str0":
      var newpStr = "str2";
      break;
    case "str1":
      var newpStr = "str7";
      break;
    case "str2":
      var newpStr = "str0";
      break;
    case "str3":
      var newpStr = "str1";
      break;
    case "str4":
      var newpStr = "str8";
      break;
    case "str5":
      var newpStr = "str4";
      break;
    default:
      alert("budui");
  }
  var newpClass = newpFill + " " + newpStr;
  el.setAttribute("class", newpClass);
}//描边填充数据转换,强耦合，需重写函数

function tranNum(num, xyf, abf, ofx, ofy, scale) {//要换算的数，X还是Y，绝对坐标还是相对坐标，X偏移，Y偏移，倍数
  if (abf == true) {
    if (xyf == false) {
      var nnum = (num - ofx) / scale;
    }
    else {
      var nnum = (num - ofy) / scale;
    }
  }
  else {
    var nnum = num / scale;
  }
  var newNum = nnum.toFixed(0);
  return newNum;
}//坐标换算,输入(int,boolean,boolean,float,float,float),返回String
function lineReplace(lineEl, offsetx, offsety, scale) {
  var x1 = lineEl.getAttribute("x1");
  var y1 = lineEl.getAttribute("y1");
  var x2 = lineEl.getAttribute("x2");
  var y2 = lineEl.getAttribute("y2");
  var num = Number(x1);
  x1 = tranNum(num, false, true, offsetx, offsety, scale);
  lineEl.setAttribute("x1", x1);
  var num = Number(x2);
  x2 = tranNum(num, false, true, offsetx, offsety, scale);
  lineEl.setAttribute("x2", x2);
  var num = Number(y1);
  y1 = tranNum(num, true, true, offsetx, offsety, scale);
  lineEl.setAttribute("y1", y1);
  var num = Number(y2);
  y2 = tranNum(num, true, true, offsetx, offsety, scale);
  lineEl.setAttribute("y2", y2);
}//直线坐标重设，输入(line元素,float,float,float)

function pathReplace(pathEl, offsetx, offsety, scale) {
  var d = pathEl.getAttribute("d");
  var newd = "", xyFlag = true, absoluteFlag = true;
  var re = /[-0123456789]/;
  var re1 = /[MLHVCSQTAZ]/;
  var re2 = /[mlhvcsqtaz]/;
  var tempN = "";
  var i;
  for (i = 0; i < d.length; i++) {
    if (re1.test(d[i])) { //大写路径
      if (!tempN == "") {
        var oldNum = Number(tempN);
        var newN = tranNum(oldNum, xyFlag, absoluteFlag, offsetx, offsety, scale);
        newd += newN;
        tempN = "";
      }
      newd += d[i];
      xyFlag = true;
      absoluteFlag = true;
    }
    else if (re2.test(d[i])) {//小写路径
      if (!tempN == "") {
        var oldNum = Number(tempN);
        var newN = tranNum(oldNum, xyFlag, absoluteFlag, offsetx, offsety, scale);
        newd += newN;
        tempN = "";
      }
      newd = newd + d[i];
      xyFlag = true;
      absoluteFlag = false;
    }
    else if (re.test(d[i])) {
      if (i == (d.length - 1)) {
        tempN += d[i];
        var oldNum = Number(tempN);
        var newN = tranNum(oldNum, xyFlag, absoluteFlag, offsetx, offsety, scale);
        newd += newN;
      }
      else {
        tempN += d[i];
      }
    }
    else {
      switch (d[i]) {
        case ",":
          if (!tempN == "") {
            var oldNum = Number(tempN);
            var newN = tranNum(oldNum, xyFlag, absoluteFlag, offsetx, offsety, scale);
            newd += newN;
            tempN = "";
          }
          newd += d[i];
          xyFlag = (!xyFlag);
          break;
        case " ":
          if (!tempN == "") {
            var oldNum = Number(tempN);
            var newN = tranNum(oldNum, xyFlag, absoluteFlag, offsetx, offsety, scale);
            newd += newN;
            tempN = "";
          }
          newd += d[i];
          xyFlag = (!xyFlag);
          break;
        default:
          newd += d[i];

      }
    }
  }

  pathEl.setAttribute("d", newd);
}//绘图路径重设

function lineReplace(lineEl, offsetx, offsety, scale) {
  var x1 = lineEl.getAttribute("x1");
  var y1 = lineEl.getAttribute("y1");
  var x2 = lineEl.getAttribute("x2");
  var y2 = lineEl.getAttribute("y2");
  var num = Number(x1);
  x1 = tranNum(num, false, true, offsetx, offsety, scale);
  lineEl.setAttribute("x1", x1);
  var num = Number(x2);
  x2 = tranNum(num, false, true, offsetx, offsety, scale);
  lineEl.setAttribute("x2", x2);
  var num = Number(y1);
  y1 = tranNum(num, true, true, offsetx, offsety, scale);
  lineEl.setAttribute("y1", y1);
  var num = Number(y2);
  y2 = tranNum(num, true, true, offsetx, offsety, scale);
  lineEl.setAttribute("y2", y2);
}//直线坐标重设，输入(line元素,float,float,float)

function polylineRe(polylineEl, offsetx, offsety, scale) {
  var points = polylineEl.getAttribute("points");
  var pArray = points.split(" ");
  var newPoints;
  var i;
  for (i = 0; i < pArray.length; i++) {
    var singleP = pArray[i].split(",");
    var px = Number(singleP[0]);
    var newPx = tranNum(px, false, true, offsetx, offsety, scale);
    var py = Number(singleP[1]);
    var newPy = tranNum(py, true, true, offsetx, offsety, scale);
    if (i == 0) {
      newPoints += (newPx + "," + newPy);
    }
    else {
      newPoints += (" " + newPx + "," + newPy);
    }
  }
  polylineEl.setAttribute("points", newPoints);
}//折线坐标重设，输入(polyline元素,float,float,float)